<?php

class Ccommon extends Controller
{
        public static function truncate_utf8_string($string, $length, $etc = '...')
        {
            $result = '';
            $string = html_entity_decode(trim(strip_tags($string)), ENT_QUOTES, 'UTF-8');
            $strlen = strlen($string);
            for ($i = 0; (($i < $strlen) && ($length > 0)); $i++)
                {
                if ($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0'))
                        {
                    if ($length < 1.0)
                                {
                        break;
                    }
                    $result .= substr($string, $i, $number);
                    $length -= 1.0;
                    $i += $number - 1;
                }
                        else
                        {
                    $result .= substr($string, $i, 1);
                    $length -= 0.5;
                }
            }
            $result = htmlspecialchars($result, ENT_QUOTES, 'UTF-8');
            if ($i < $strlen)
                {
                        $result .= $etc;
            }
            return $result;
        }
        
        public static function check($temp)
        {
                if($temp==0)
                    return "未参加";
                else
                    return "<font color='green'>已参加</font>";
        }

        public static function sms_float($temp)
        {
                if($temp==1)
                     return "<font color='green'>已发送</font>";
                else
                   return "发送失败";
        }
        
         public static function ctype($temp)
        {
                if($temp==0)
                    return "未来";
                else if($temp==1){
                     return "已来";
                }
                else if($temp==3){
                     return "已取消";
                }

                 return "";
        }
        
        
        public static function sms($temp)
        {
                if($temp==1)
                    return "报名短信";
                else if($temp==2)
                    return "电子门票短信";
                else
                    return "友情提示";

        }
        
        public static function ctypeList(){
            
            return  array('1'=>'报名短信',
                            '2'=>'电子门票短信',
                            '3'=>'友情提示',);
        }
    
        public static function smsMessage($s_phone,$s_txt){
                require_once("nusoap.php");
                $soapclient = new nusoap_client("http://www.shinho.com.cn/sendsms/Service1.asmx?wsdl",true);
                $soapclient->soap_defencoding = 'UTF-8';
                $soapclient->decode_utf8 = false;
                $parameters = array("phone"=>$s_phone, "s_txt"=>$s_txt);
                $result = $soapclient->call('SendSMS',$parameters);
                return $result;
        }
          public static function smsYX($s_phone,$s_txt){
                        require_once("nusoap.php");
                        $soapclient = new nusoap_client("http://www.shinho.com.cn/sendsms/Service1.asmx?wsdl",true);
                        $soapclient->soap_defencoding = 'UTF-8';
                        $soapclient->decode_utf8 = false;
                        $url="http://wx.shiyujia.com/Ex/sign/index.php/default/index";
//                        $s_txt = "‘社会大课堂活动’网络报名火热进行中，请点击链接，填写详细报名信息，‘欣和爱生活食育体验馆’期待您的到来！链接地址：http://dwz.cn/1eAUkT。以上";
                        $parameters = array("phone"=>$s_phone, "s_txt"=>$s_txt);
                        return $result = $soapclient->call('send_YX_SMS',$parameters);
        }
        
        public static function  url_short($url){
        $ch=curl_init();
        curl_setopt($ch,CURLOPT_URL,"http://dwz.cn/create.php");
        curl_setopt($ch,CURLOPT_POST,true);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        $data_url=array('url'=>$url);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$data_url);
        $strRes=curl_exec($ch);
        curl_close($ch);
        $arrResponse=json_decode($strRes,true);
        if($arrResponse['status']==0)
        {
            /**错误处理*/
            echo iconv('UTF-8','GBK',$arrResponse['err_msg'])."\n";
        }
        /** tinyurl */
        return $arrResponse['tinyurl'];
    }
        
        
}
